<template>
  <div class="sidebar">
    <el-radio-group v-model="isCollapse" style="margin-bottom: 20px">
      <el-radio-button :label="false">展开</el-radio-button>
      <el-radio-button :label="true">收起</el-radio-button>
    </el-radio-group>
    <el-menu
      :default-active="DefaultActive"
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose"
      :collapse="isCollapse"
    >
      <el-submenu
        :index="index.toString() + 1"
        v-for="(item, index) in Submenu"
        :key="index"
      >
        <template slot="title">
          <i :class="item.icon"></i>
          <span slot="title">{{ item.title }}</span>
        </template>
        <el-menu-item-group v-for="(item, index) in item.children" :key="index">
          <el-menu-item :index="index.toString()">
            {{ item.title }}
          </el-menu-item>
        </el-menu-item-group>
        <el-submenu
          :index="index.toString() + 2"
          v-for="(item, index) in item.childrens"
          :key="'info2' + index"
        >
          <span slot="title">{{ item.title }}</span>
          <el-menu-item
            :index="index.toString()"
            v-for="(item, index) in item.children"
            :key="index"
            >{{ item.title }}</el-menu-item
          >
        </el-submenu>
      </el-submenu>

      <el-menu-item
        :index="index.toString()"
        v-for="(item, index) in Data"
        :key="'info3' + index"
      >
        <i :class="item.icon"></i>
        <span slot="title">{{ item.title }}</span>
      </el-menu-item>
    </el-menu>
  </div>
</template>
<script>
module.exports = {
  data() {
    return {
      isCollapse: true,
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      // console.log(key, keyPath);
      let params = { key, keyPath };
      this.$emit("open", params);
    },
    handleClose(key, keyPath) {
      // console.log(key, keyPath);
      let params = { key, keyPath };
      this.$emit("close", params);
    },
  },
  props: {
    //当前激活菜单的 index
    DefaultActive: {
      type: String,
      default: "1-4-1",
    },
    Submenu: {
      type: Array,
      default: () => [
        {
          title: "导航一",
          icon: "el-icon-location",
          children: [
            {
              title: "选项1",
            },
            {
              title: "选项2",
            },
          ],
          childrens: [
            {
              title: "导航",
              icon: "el-icon-location",
              children: [
                {
                  title: "选项",
                },
                {
                  title: "选项",
                },
              ],
            },
          ],
        },
      ],
    },
    Data: {
      type: Array,
      default: () => [
        {
          title: "导航二",
          icon: "el-icon-menu",
        },
        {
          title: "导航三",
          icon: "el-icon-document",
        },
      ],
    },
  },
};
</script>